<?php 
class Hoatdong extends MX_Controller {

    private $table_name_path = 'hoatdong';
    private $table_name = '';

    public function __construct() {
        parent::__construct();
        $this->my_layout->setLayout("layout/frontend");
        //$this->load->helper('url');
        $this->load->helper(array("url",'form'));
        $this->load->library('form_validation');
        $this->load->library('pagination');
        $this->load->model('hoatdong_model');
        $this->load->model('center_model');
    }
    private $limit = 5;
    private $limitComment = 10;
    public function index() {
        $activity = $this->hoatdong_model->load_activity();
        $data['type_of_center'] = $this->center_model->get_type();
        $data['idType'] = NULL;
        $config['base_url'] = base_url() . 'index.php/website/hoatdong/index';
        $config['total_rows'] = $this->hoatdong_model->load_activity()->num_rows();
        $config['per_page'] = 5;
        $config['uri_segment'] = 4;
        $config['num_links'] = 5;
        $config['next_link'] = 'Next »';
        $config['prev_link'] = '« Prev';
        $config['full_tag_open'] = '<ul class="pagination">';
        $config['full_tag_close'] = '</ul>';
        $config['prev_tag_open'] = '<li>';
        $config['prev_tag_close'] = '</li>';
        $config['next_link'] = '&raquo;';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="active"><a href="#">';
        $config['cur_tag_close'] = '</a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';

        $this->pagination->initialize($config);

        $data['link'] = $this->pagination->create_links();
        if($activity->num_rows()==0)
        {
          $data['notice']="Không có hoạt động nào!";
          $data['activity']=$activity->result_array();
          $this->my_layout->view("frontend/hoatdong/list_hoatdong_view", $data);
        }
        else{
        $data['notice']=null;
        $data['activity']= $activity->result_array();
        $this->my_layout->view("frontend/hoatdong/list_hoatdong_view", $data);
        }
        
        
    }

    function addData() {
        $data['link_back'] = anchor($this->table_name_path . '/index', 'Trá»Ÿ vá»? trang ' . $this->table_name, array('class' => 'back'));
        if ($this->form_validation->run() == FALSE) {
            $this->my_layout->view("frontend/hoatdong/add_hoatdong_view", $data);
        } else {
            $data = array(
                'name' => $this->input->post('name'),
                'discription' => $this->input->post('discription'),
                'startday' => $this->input->post('startday'),
                'endday' => $this->input->post('endday'),
                'id_center' => $this->input->post('id_center'),
//                'rating' => $this->input->post('rating'),
            );
            $this->hoatdong_model->add($data);

            // set form input name="id"
            // $this->form_validationvalidation->id = $id;
            redirect($this->table_name_path . '/index', 'refresh');
            if ($this->input->post('add') === "Gui") {
            $this->my_layout->view("frontend/hoatdong/hoatdong_view", $data);
        }
//        $this->my_layout->view("frontend/add_hoatdong_view");
        }
    }
    function load_by_id($id, $itemNumber = NULL) {
        //load comment
        $this->load->model('comment_article_model');
        $commentData = $this->comment_article_model->loadByArticle($id, $this->limitComment, $itemNumber);
        $comment['data'] = $commentData->result_array();
        $data['activeTab1'] = ($itemNumber == NULL) ? TRUE : FALSE;
        $data['showArticle'] = ($itemNumber == NULL) ? TRUE : FALSE;
        
        //paging commment
        $config['base_url'] = base_url() . 'index.php/website/article/id/' . $id . '/';
        $config['total_rows'] = $this->comment_article_model->countAll();
        $config['per_page'] = $this->limitComment;
        $config['uri_segment'] = 5;
        $config['num_links'] = 5;
        $config['next_link'] = 'Next »';
        $config['prev_link'] = '« Prev';
        $config['full_tag_open'] = '<ul class="pagination">';
        $config['full_tag_close'] = '</ul>';
        $config['prev_tag_open'] = '<li>';
        $config['prev_tag_close'] = '</li>';
        $config['next_link'] = '&raquo;';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="active"><a href="#">';
        $config['cur_tag_close'] = '</a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';

        $this->pagination->initialize($config);

        $comment['link'] = $this->pagination->create_links();
        $data['comment'] = $comment;
        
        $data['type_of_center'] = $this->center_model->get_type();
        $data['idType'] = NULL;
        $actv = $this->hoatdong_model->get_by_id($id);
        $data['activity'] = $this->hoatdong_model->get_by_id($id);
        $data['listActForCenter'] = $this->hoatdong_model->getActivitiesCenter($data['activity']['id_center']);
        $this->hoatdong_model->increate_view($id,$data['activity']['view']);
        $this->my_layout->view('frontend/hoatdong/hoatdong_view',$data);
    }
    function load_by_type($id_type)
    {
       // $type= $this->hoatdong_model->get_by_type($id_type)->row_array();
       // $data['id_type'] = $type['id_type_center'];
       // $data['type_of_center'] = $this->hoatdong_model->get_by_type($id_type)->result_array();
        /*$data['activity'] = $this->hoatdong_model->get_by_type($id_type)->result_array();
        $config['base_url'] = base_url() . 'index.php/website/hoatdong/load_by_type/'.$id_type.'/';
        $config['total_rows'] = $this->hoatdong_model->get_by_type($id_type)->num_rows();
        $config['per_page'] = 5;
        $config['uri_segment'] = 4;
        $config['num_links'] = 5;
        $config['next_link'] = 'Next »';
        $config['prev_link'] = '« Prev';
        $config['full_tag_open'] = '<ul class="pagination">';
        $config['full_tag_close'] = '</ul>';
        $config['prev_tag_open'] = '<li>';
        $config['prev_tag_close'] = '</li>';
        $config['next_link'] = '&raquo;';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="active"><a href="#">';
        $config['cur_tag_close'] = '</a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';

        $this->pagination->initialize($config);
        $data['link'] = $this->pagination->create_links();
        $data['type_of_center'] = $this->center_model->get_type();
        $data['idType'] = $id_type;
        $this->my_layout->view('frontend/hoatdong/list_hoatdong_view',$data);*/
       $activity = $this->hoatdong_model->get_by_type($id_type);
        $data['activity'] = NULL;
        if ($activity->num_rows()>0){
            $data['activity'] = $activity->result_array();
            $data['notice'] = null;
        }else{
            $data['notice'] = 'Không có hoạt động nào!';
        }
        
        //pageination
        $config['base_url'] = base_url() . 'index.php/website/hoatdong/load_by_type/'.$id_type.'/';
        $config['total_rows'] = $this->hoatdong_model->get_by_type($id_type)->num_rows();
        $config['per_page'] = 5;
        $config['uri_segment'] = 4;
        $config['num_links'] = 5;
        $config['next_link'] = 'Next »';
        $config['prev_link'] = '« Prev';
        $config['full_tag_open'] = '<ul class="pagination">';
        $config['full_tag_close'] = '</ul>';
        $config['prev_tag_open'] = '<li>';
        $config['prev_tag_close'] = '</li>';
        $config['next_link'] = '&raquo;';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="active"><a href="#">';
        $config['cur_tag_close'] = '</a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';

        $this->pagination->initialize($config);

        $data['link'] = $this->pagination->create_links();
        
        $data['type_of_center'] = $this->center_model->get_type();
        $data['idType'] = $id_type;
        
        $this->my_layout->view('frontend/hoatdong/list_hoatdong_view',$data);
    }
}

?>
